'''
鼠标操作的方法：
(1)perform()			执行所有ActionChains中存储的行为
(2)double_click()		鼠标左键双击
(3)context_click()	鼠标右键单击
(4)move_to_element()				鼠标悬停
(5)drag_and_drop(source，target)	鼠标拖动
(6)	key_down()  键按下
(7)	key_up()    键抬起
(8)实现思路：
①需要引入ActionChains类
②然后定位相关元素
③初始化ActionChains()对象，调用相关鼠标操作方法，然后执行
'''
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from time import sleep
chrome_location = r'D:\chrom browser\chrome-win\chrome.exe'
options = webdriver.ChromeOptions()
options.binary_location = chrome_location
dr = webdriver.Chrome(options=options)
dr.get(r'https://www.baidu.com/')
sleep(1)
#左键双击
dr.find_element(By.ID,'kw').send_keys('aaaaaa')
ele = dr.find_element(By.ID, 'kw')
ActionChains(dr).double_click(ele).perform()
sleep(2)
#键盘单击
dr.find_element(By.ID,'kw').send_keys('aaaaaa')
ele = dr.find_element(By.ID, 'kw')
ActionChains(dr).context_click(ele).perform()
sleep(2)
#鼠标的悬停
ele = dr.find_element(By.CSS_SELECTOR,'#s-top-left > div > a')
ActionChains(dr).move_to_element(ele).perform()
sleep(3)
#鼠标拖拽
# ele1=dr.find_element(By.ID,'value1')
# ele2=dr.find_element(By.ID,'value2')
# ActionChains(dr).drag_and_drop(ele1,ele2).perform()
# sleep(2)